/**
 * 
 */
package me.myachievements.web.administration.account;

import org.apache.wicket.PageParameters;
import org.apache.wicket.markup.html.panel.FeedbackPanel;
import org.apache.wicket.spring.injection.annot.SpringBean;

import me.myachievements.persistence.account.Account;
import me.myachievements.persistence.account.AccountPersistenceManager;

import me.myachievements.web.ErrorPage;
import me.myachievements.web.account.AccountForm;
import me.myachievements.web.account.UpdateAccountForm;
import me.myachievements.web.administration.AdministrationPage;

/**
 * @author besseym
 *
 */
public class UpdateAccountPage extends AdministrationPage {
	
	@SpringBean(name="accountPersistenceManager")
	AccountPersistenceManager accountPersistenceManager;

	/**
	 * 
	 */
	public UpdateAccountPage(PageParameters pageParameters) {
		
		Account account = null; 
		if(!pageParameters.containsKey("id")) {
			this.setResponsePage(new ErrorPage());
			return;
		}
		
		String id = pageParameters.getString("id"); 
		account = accountPersistenceManager.read(Long.parseLong(id));
		
		add(new FeedbackPanel("feedback"));
		
		AccountForm accountForm = new UpdateAccountForm("update_account_form", "Update Account", account);
		add(accountForm);
	}

}
